<template>
  <h1>一个人的信息</h1>
  <h2 v-show="person.name">姓名：{{person.name}}</h2>
  <h2>年龄：{{person.age}}</h2>
  <h2 v-show="person.sex">性别：{{person.sex}}</h2>
  <h2>工作：{{person.job.type}}</h2>
  <h2>薪资：{{person.job.salary}}</h2>
  <h2>测试c：{{person.job.a.b.c}}</h2>
  <h2>爱好：{{person.job.hobby}}</h2>
  <button @click="changePerson">修改人的信息</button>
  <button @click="addSex">添加一个sex</button>
  <button @click="deleteName">删除name</button>
</template>

<script>
import {reactive} from 'vue'
export default {
  name: 'App',
  setup(){
    //数据
    let person=reactive({
      name:"张三",
      age:18,
      job:{
        type:'前端工程师',
        salary:'10k',
        a:{
          b:{
            c:1
          }
        },
        hobby:['吃饭','唱歌','看电影']
      }

    })

    function changePerson(){
      person.name="李四"
      person.age=25
      person.job.type='UI设计师'
      person.job.salary='60k'
      person.job.a.b.c=666
      person.job.hobby[0]="跳舞"
    }

    function addSex(){
      person.sex='男'
    }

    function deleteName(){
      delete person.name
    }


    //返回一个对象（常用）
    return{
      person,
      changePerson,
      addSex,
      deleteName
    }
  }
}
</script>
